cmake_minimum_required(VERSION 3.20)

find_package(PkgConfig REQUIRED)

project(GtkLearn)

# set(GTKVER "4")

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/build/bin/")
# set(CMAKE_C_FLAGS "cc ${CMAKE_C_FLAGS}")

pkg_check_modules(GTK "gtk+-3.0")
pkg_check_modules(GTK4 "gtk4")

aux_source_directory(. SRC)

foreach(TSRC ${SRC})
    get_filename_component(FNAME ${TSRC} NAME_WLE)
    get_filename_component(FEXT ${TSRC} EXT)
    
    if(FEXT STREQUAL ".c")
        add_executable("${FNAME}.out" ${TSRC})
        target_link_directories("${FNAME}.out" PRIVATE ${GTK_LIBRARY_DIRS})
        target_include_directories("${FNAME}.out" PRIVATE ${GTK_INCLUDE_DIRS})
        target_link_libraries("${FNAME}.out" ${GTK_LIBRARIES})
        message("build the ${TSRC} with ${GTK_LIBRARIES}")
    elseif(FEXT STREQUAL ".4.c")
        add_executable("${FNAME}.out" ${TSRC})
        target_link_directories("${FNAME}.out" PRIVATE ${GTK4_LIBRARY_DIRS})
        target_include_directories("${FNAME}.out" PRIVATE ${GTK4_INCLUDE_DIRS})
        target_link_libraries("${FNAME}.out" ${GTK4_LIBRARIES})
        message("build the ${TSRC} with ${GTK4_LIBRARIES}")
    endif()
endforeach()
